<template>
  <rx-dialog @handOk="handleSubmit" @cancel="cancel">
    <rx-layout>
      <div slot="center">
        <a-form :form="form">
          <a-form-item style="display: none;">
            <a-input v-decorator="['treeId']"/>
            <a-input v-decorator="['parentId',{initialValue:mdl.parentId}]"/>
            <a-input v-decorator="['appId',{initialValue:mdl.appId?mdl.appId:curApp.appId}]"/>
            <a-input v-decorator="['catKey',{initialValue:mdl.catKey?mdl.catKey:curApp.catKey}]"/>
          </a-form-item>
          <a-form-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('form.showType','上级名称')"
                       v-if="mdl.parentName && mdl.parentName!=''">
            <a-input :disabled="true" v-model="mdl.parentName"/>
          </a-form-item>
          <a-form-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('form.name','名称')">
              <rx-input-i18n :placeholder="i18n('form.name','名称')" :isDecorator="true"
                             @blur="getPinyinByName" v-decorator="['name', {rules: [{required: true, message: i18n('form.name','名称','input')}]}]"/>
          </a-form-item>
          <a-form-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('form.alias','节点别名')">
            <a-input :placeholder="i18n('form.alias','节点别名')" v-decorator="['alias', {rules: [{required: true, message: i18n('form.alias','节点别名','input')}]}]"/>
          </a-form-item>

          <a-form-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('form.sn','序号')">
            <a-input-number :min="0" :max="10000" :placeholder="i18n('form.sn','序号')"
                            v-decorator="['sn', {
                          initialValue:1,
                          rules: [{required: true, message: i18n('form.sn','序号','input')}]}]"/>
          </a-form-item>
            <a-form-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="exportI18n('export.isExport','是否导出')">
                <a-radio-group buttonStyle="solid"  v-decorator="['isExport', {initialValue: 1, rules: [{required: false, message: '请输入展示类型'}]}]">
                    <a-radio-button :value="1">{{exportI18n('export.yes','是')}}</a-radio-button>
                    <a-radio-button :value="0">{{exportI18n('export.no','否')}}</a-radio-button>
                </a-radio-group>
        </a-form-item>
        <a-form-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" label="所属应用"
                     v-if="curApp.appName && curApp.appName !=''" v-show="false">
            <a-input :disabled="true" v-model="curApp.appName"/>
        </a-form-item>
        <a-form-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('form.showType','展示类型')"
                     v-show="displayDataShowType && (curApp.catKey=='DIC' || mdl.catKey=='DIC') ">
            <a-radio-group buttonStyle="solid"  v-decorator="['dataShowType', {initialValue:'FLAT',rules: [{required: false, message: i18n('form.showType','展示类型','select')}]}]">
              <a-radio-button value="FLAT">{{i18n('form.flat','平铺')}}</a-radio-button>
              <a-radio-button value="TREE">{{i18n('form.tree','树型')}}</a-radio-button>
            </a-radio-group>
         </a-form-item>
        </a-form>
      </div>
    </rx-layout>

  </rx-dialog>
</template>
<script>
  import SysTreeApi from '@/api/system/core/sysTree';
  import SysTreeCatApi from '@/api/system/core/sysTreeCat'
  import {BaseForm,RxDialog,RxLayout,RxInputI18n } from "@lowcode/jpaas-common-lib";
  export default {
    name: 'SysTreeEdit',
    mixins:[BaseForm],
    props: {
      data:Object,
      layerid: String,
      lydata: Object,
      destroy: Function,
      displayDataShowType:{
        type:Boolean,
        default:false
      }
    },
    components: {
      RxDialog,
      RxLayout,
      RxInputI18n
    },
    data() {
      return {
        catList:[],
      }
    },
    created() {
      // SysTreeCatApi.getCatList().then(res => {
      //   console.log(res)
      //   this.catList=res;
      // })
    },
    methods: {
      i18n(name,text,key){
          return this.$ti18(name,text,"SysTree",key);
      },
        exportI18n(name,text,key){
            return this.$ti18(name,text,"appExport",key);
        },
      onload_(vals){
        if(!this.pkId){
          Object.assign(this.mdl,this.data);
        }
        if(this.mdl.parentName){
            this.mdl.parentName=this.$i18(this.mdl.parentName,'分类名称');
        }
      },
      get(id){
        return SysTreeApi.get(id);
      },
      save(values){
          if(!this.pkId &&this.data.rightJson){
              values.rightJson=this.data.rightJson;
          }
        return SysTreeApi.save(values);
      },
        getPinyinByName(){
            let name=this.form.getFieldsValue().name
            if (!name){
                return;
            }
            if (this.form&&this.form.getFieldsValue().alias){
                return;
            }
            this.getPinyin(this.$i18(name)).then(res => {
                //去除不可见的特殊符号
                if(res){
                    res=res.replace(/\u200B/g,'');
                }
                this.form.setFieldsValue({alias:res})
            })
        },

    }
  }


</script>
<style scoped>
  *>>>.ant-row.ant-form-item:last-child{
      margin-bottom: 0;
  }
</style>